<!doctype html>
<html lang="zh_CN">
	<head>
		{{template "header"}}
	</head>

	<body>
		<!-- 顶部开始 -->
		<div class="container">
			<div class="logo">
				<a href="/index">Gobase</a>
			</div>
			<div class="left_open">
				<i title="展开左侧栏" class="iconfont">&#xe699;</i>
			</div>
			<ul class="layui-nav left" lay-filter="">
				{{ range .navList}}
				<li class="layui-nav-item" data-value="{{.Id}}">
					<a href="javascript:void(0);" onclick="navMenuClick('{{.Id}}')" class="nav-menu">{{.Title}}</a>
				</li>
				{{end}}
			</ul>
			<ul class="layui-nav right" lay-filter="">
				<li class="layui-nav-item">
					<a href="javascript:void(0);">{{ .loginAccount }}</a>
					<dl class="layui-nav-child">
						<!-- 二级菜单 -->
						<dd>
							<a onclick="WeAdminShow('个人信息','/myinfo', 800,450)">个人信息</a>
						</dd>
						<dd>
							<a onclick="WeAdminShow('修改登录密码','/changePwd', 425,410)">修改密码</a>
						</dd>
						<dd>
							<a class="loginout" id="_logoutbtn" href="javascript:void(0)">退出</a>
						</dd>
					</dl>
				</li>
				<!-- <li class="layui-nav-item to-index">
					<a href="/">前台首页</a>
				</li> -->
			</ul>

		</div>
		<!-- 顶部结束 -->
		<!-- 中部开始 -->
		<!-- 左侧菜单开始 -->
		<div class="left-nav">
			<div id="side-nav">
				<ul id="nav">
				</ul>
			</div>
		</div>

		<!-- 左侧菜单结束 -->
		<!-- 右侧主体开始 -->
		<div class="page-content">
			<div class="layui-tab tab" lay-filter="wenav_tab" id="WeTabTip" lay-allowclose="true">
				<ul class="layui-tab-title">
					<li>我的桌面</li>
				</ul>
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show">
						<iframe src='/welcome' frameborder="0" scrolling="yes" class="weIframe"></iframe>
					</div>
				</div>
			</div>
		</div>
		<div class="page-content-bg"></div>
		<!-- 右侧主体结束 -->
		<!-- 中部结束 -->
		<!-- 底部开始 -->
		<div class="footer">
			<div class="copyright">Copyright ©2018 Gobase后台管理系统 All Rights Reserved</div>
		</div>
		<!-- 底部结束 -->
	</body>
	<!--Tab菜单右键弹出菜单-->
	<ul class="rightMenu" id="rightMenu">
        <li data-type="fresh">刷新</li>
        <li data-type="current">关闭当前</li>
        <li data-type="other">关闭其它</li>
        <li data-type="all">关闭所有</li>
    </ul>

	{{template "jsfile"}}
	<script type="text/javascript">
		layui.use(['jquery'], function(){
			var $ = layui.jquery;

			//jsonList转jsonTreeList
			function getListToTree(data, pid){
				var result = [];
				if(!data || data.length <= 0){
					return result;
				}

				for(var i=0,len=data.length;i<len;i++){
					node = data[i];
					if(node && node.ParentId == pid){
						data.splice(i--,1);
						len--;
						result.push({
							title:node.Title,
							pid:node.ParentId,
							url:node.Url,
							type:node.Category,
							icon:node.Icon,
							children:getListToTree(data, node.Id)
						});
					}
				}
				return result;
			}

			var menuJsonList = '';
			var noAction = '<a href="javascript:void(0);" >';
			var iconStr =  '<i class="layui-icon '; //'<i class="iconfont">&#xe6b8;</i>';
			function getMenuStr(menuObj){
				var menuStr = '';
				menuStr += '<li>' + (menuObj.type==2?noAction: '<a _href="'+menuObj.url+'">');
				menuStr += iconStr + (menuObj.icon)+'"></i><cite>'+(menuObj.title)+'</cite>';
				if(menuObj.type == 2){
					menuStr += '<i class="iconfont nav_right">&#xe697;</i>'
				}
				menuStr += '</a>';
				return menuStr;
			}

			function getLeftMenu(navMenuId){
				myMenuList = getListToTree(menuJsonList, navMenuId);

				var htmlStr = "";
				for(var i=0,len=myMenuList.length;i<len;i++){
					var m = myMenuList[i];
					htmlStr += getMenuStr(m);

					if(m.children.length > 0){
						htmlStr += '<ul class="sub-menu">';
						for(var k=0,len1=m.children.length; k<len1; k++){
							m1 = m.children[k];
							htmlStr += getMenuStr(m1)+'</li>';
						}
						htmlStr += '</ul>';
					}
					htmlStr += '</li>';
				}
				$("#nav").html(htmlStr);
			}

			function showLeft(){
				var topNavs = $("ul.layui-nav.left>li.layui-nav-item");
				if(topNavs && topNavs.length>0){
					getLeftMenu($(topNavs[0]).attr("data-value"));
				}else{
					$("#nav").html('');
				}
			}
			if(!menuJsonList){
				$.get('/getMenus',{},function(result){
					if(result.status && result.data){
						menuJsonList = JSON.parse(result.data);
						showLeft();
					}
				})
			}else{
				showLeft();
			}
		});

		layui.config({
		  base: '/static/js/'
		  ,version: '101100'
		}).use(['admin', 'jquery'],function(){
			var $ = layui.jquery;
			$("#_logoutbtn").click(function(){
				$.post("/login/logout",{},function(result){
					if(result.status){
						location.replace("/login/index");
					}else{
						layer.msg(result.message);
					}
				},"json");
				return false;
			});
		});
	</script>
</html>